package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.puti.common.core.constant.HttpStatus;
import com.puti.common.core.domain.R;
import com.puti.doctor.domian.GoodsOrder;
import com.puti.doctor.service.IGoodsOrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;

import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 商品-订单 商品-订单Controller
 *
 * @author puti
 * @date 2021-04-21
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class GoodsOrderController extends BaseController
{
    @Autowired

    private IGoodsOrderService goodsOrderService;

    /**
     * 查询商品-订单 商品-订单列表
     */

    @GetMapping("/list")
    public TableDataInfo list(GoodsOrder goodsOrder)
    {
        startPage();
        List<GoodsOrder> list = goodsOrderService.selectGoodsOrderList(goodsOrder);
        return getDataTable(list);
    }

    /**
     * 导出商品-订单 商品-订单列表
     */
    @PreAuthorize(hasPermi = "system:order:export")
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsOrder goodsOrder) throws IOException
    {
        List<GoodsOrder> list = goodsOrderService.selectGoodsOrderList(goodsOrder);
        ExcelUtil<GoodsOrder> util = new ExcelUtil<GoodsOrder>(GoodsOrder.class);
        util.exportExcel(response, list, "商品-订单 商品-订单数据");
    }

    /**
     * 获取商品-订单 商品-订单详细信息
     */
    @PreAuthorize(hasPermi = "system:order:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(goodsOrderService.selectGoodsOrderById(orderId));
    }

    /**
     * 新增商品-订单 商品-订单
     */
    @PreAuthorize(hasPermi = "system:order:add")
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsOrder goodsOrder)
    {
        return toAjax(goodsOrderService.insertGoodsOrder(goodsOrder));
    }

    /**
     * 修改商品-订单 商品-订单
     */
    @PreAuthorize(hasPermi = "system:order:edit")
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsOrder goodsOrder)
    {
        return toAjax(goodsOrderService.updateGoodsOrder(goodsOrder));
    }

    /**
     * 删除商品-订单 商品-订单
     */
    @PreAuthorize(hasPermi = "system:order:remove")
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(goodsOrderService.deleteGoodsOrderByIds(orderIds));
    }

    /**
     * 我的订单-待付款：用户未支付商品；
     */
    @GetMapping("puti-pati/{dockerId}")
    public R selectDockerById(@PathVariable("dockerId") String dockerId){
        List<GoodsOrder> goodsOrders = goodsOrderService.selectDockerById(dockerId);
        if(goodsOrders!=null){
            return R.restResult(goodsOrders, HttpStatus.SUCCESS,"查询成功");
        }
        return R.restResult(null,HttpStatus.SUCCESS,"查询失败");
    }

    /**
     * 我的订单-待收货：用户已支付未收货商品；
     */
    @GetMapping("puti-patients/{dockerId1}")
    public R selectGoodsById(@PathVariable("dockerId1") String dockerId1){
        List<GoodsOrder> goodsOrders = goodsOrderService.selectGoodsById(dockerId1);
        if(goodsOrders!=null){
            return R.restResult(goodsOrders,HttpStatus.SUCCESS,"查询成功");
        }
        return R.restResult(null,HttpStatus.SUCCESS,"查询失败");
    }

    /**
     * 我的订单-待评价：用户已收货为评价商品；
     */
    @GetMapping("puti-patient/{patientId}")
    public R selectparientId(@PathVariable("patientId")String patientId){
        List<GoodsOrder> goodsOrders = goodsOrderService.selectparientId(patientId);
        if(goodsOrders!=null){
            return R.restResult(goodsOrders,HttpStatus.SUCCESS,"查询成功");
        }
        return R.restResult(null,HttpStatus.SUCCESS,"查询失败");
    }

    /**
     * 我的订单-申请售后：商家发出商品后即可申请售后；
     */
    @GetMapping("puti-receipt/{receiptId}")
    public List<GoodsOrder> selectReceiptid(@PathVariable("receiptId")String receiptId){
        return goodsOrderService.selectReceiptid(receiptId);
    }

    /**
     * 我的订单-评价：用户已确认收货未评价商品；
     */
    @GetMapping("puti-status/{statusId}")
    public List<GoodsOrder> selectStatusById(@PathVariable("statusId") String statusId) {
        return goodsOrderService.selectStatusById(statusId);
    }

    @GetMapping("puti-count")
    public Long seleckSeckillnum(){
        return goodsOrderService.seleckSeckillnum();
    }
}
